﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;

public class Testss
{
    public int id
    {
        get;
        private set;
    }

    public override string ToString()
    {
        return id.ToString();

    }
}

public class RefectChange : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        Testss a = new Testss();
        Testss b = new Testss();

        Type type = typeof(Testss);
        PropertyInfo propertyInfo = type.GetProperty("id");
        propertyInfo.SetValue(a, -1, null);
        propertyInfo.SetValue(b, -2, null);


        Action<Testss,int> act = Delegate.CreateDelegate(typeof(Action<Testss, int>), propertyInfo.GetSetMethod(true)) as Action<Testss, int>;
        act(a, 1);
        act(b, 2);


        ///批量实例化对象的快速方法
        object obj = Activator.CreateInstance(type);
        MethodInfo mcMi = typeof(object).GetMethod("MemberwiseClone", BindingFlags.NonPublic | BindingFlags.Instance);
        Func<object, object> mcAct = Delegate.CreateDelegate(typeof(Func<object, object>), mcMi) as Func<object, object>;
        List<object> list = new List<object>(100);
        for (int i = 0; i < 100; i++)
        {
            list.Add(mcAct(obj));
        }
        for (int i = 0; i < list.Count-1; i++)
        {

            Debug.Log(list[i].Equals(list[i+1]));
        }




    }
}
